import {
  getUser,
  login,
  getProfile
} from '../../../api/account'

export const actions = {
  login: async ({ commit }, params) => {
    const { data } = await login(params)
    const { accessToken } = data
    commit('setToken', accessToken)
  },
  getUser: async ({ commit }, id) => {
    const { data } = await getUser(id)
    const { extraProperties } = data
    const { role } = extraProperties
    commit('setUser', data)
    commit('setRole', role)
  },
  getProfile: async ({ commit }) => {
    const { data } = await getProfile()
    const { extraProperties } = data
    const { role } = extraProperties
    commit('setUser', data)
    commit('setRole', role)
  }
}
